package com.pug.controller;

import com.pug.service.BusinessService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 飞哥
 * @Title: 学相伴出品
 * @Description: 飞哥B站地址：https://space.bilibili.com/490711252
 * 记得关注和三连哦！
 * @Description: 我们有一个学习网站：https://www.kuangstudy.com
 * @date 2022-07-06$ 20:01$
 */
@Slf4j
@RestController
@RequiredArgsConstructor
public class BusinessController {

    private final BusinessService businessService;

    @GetMapping("/purchase/commit")
    public String orderCommit() {
        try {
            businessService.purchase(2L, 10001L, 1);
            return "success";
        } catch (Exception ex) {
            return ex.getMessage();
        }
    }

    @GetMapping("/purchase/rollback")
    public String orderCommit(Long userId, Long productId, Integer count) {
        try {
            businessService.purchase(1L, 10001L, 1);
            return "success";
        } catch (Exception ex) {
            return ex.getMessage();
        }
    }

}
